Document the "orientation" option.
authorMatthias Clasen <mclasen@redhat.com>
Mon, 2 Jul 2007 14:47:45 +0000 (14:47 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 2 Jul 2007 14:47:45 +0000 (14:47 +0000)
2007-07-02  Matthias Clasen <mclasen@redhat.com>

        * gdk-pixbuf.c (gdk_pixbuf_get_option): Document the
        "orientation" option.

        * gdk-pixbuf.symbols:
        * gdk-pixbuf-core.h:
        * gdk-pixbuf-util.c (gdk_pixbuf_apply_embedded_orientation):
        New function to handle Exif orientation information in
        tiff and jpeg images.  (#439567, Michael Chudobiak)

svn path=/trunk/; revision=18340

docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-core.h
gdk-pixbuf/gdk-pixbuf-util.c
gdk-pixbuf/gdk-pixbuf.c
gdk-pixbuf/gdk-pixbuf.symbols

index 92c1972d55e4f1589be1d30062b2bad92ad2fc01..f441f65d09740547f07868ff8850508e03a6e26a 100644 (file)
@@ -108,6 +108,7 @@ gdk_pixdata_to_csource
 gdk_pixbuf_add_alpha
 gdk_pixbuf_copy_area
 gdk_pixbuf_saturate_and_pixelate
+gdk_pixbuf_apply_embedded_orientation
 gdk_pixbuf_fill
 </SECTION>
 
index b36a38c189ea928450feb9979d9e18c79d007ea9..db30ed951c777f987d01fc94974b85763f4b339f 100644 (file)
@@ -1,3 +1,14 @@
+2007-07-02  Matthias Clasen <mclasen@redhat.com>
+
+       * gdk-pixbuf.c (gdk_pixbuf_get_option): Document the
+       "orientation" option.
+
+       * gdk-pixbuf.symbols:
+       * gdk-pixbuf-core.h:
+       * gdk-pixbuf-util.c (gdk_pixbuf_apply_embedded_orientation):
+       New function to handle Exif orientation information in 
+       tiff and jpeg images.  (#439567, Michael Chudobiak)
+
 2007-06-19  Matthias Clasen <mclasen@redhat.com>
 
        * === Released 2.11.4 ===
index f7abfd0c7f3576e502c2c5e9bcac2f60ae67bccf..4ae589526bc74d66538c09320672c1471ba4f87a 100644 (file)
@@ -231,6 +231,8 @@ void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src,
                                        gfloat           saturation,
                                        gboolean         pixelate);
 
+/* Transform an image to agree with its embedded orientation option / tag */
+GdkPixbuf *gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src);
 
 G_CONST_RETURN gchar * gdk_pixbuf_get_option (GdkPixbuf   *pixbuf,
                                               const gchar *key);
index c25576546cffe57382fb4281bfbe01b8f8879939..aeee33dbee28facc5615a09b6e5cc014cfd7d543 100644 (file)
@@ -245,6 +245,88 @@ gdk_pixbuf_saturate_and_pixelate(const GdkPixbuf *src,
         }
 }
 
+
+/**
+ * gdk_pixbuf_apply_embedded_orientation:
+ * @src: A #GdkPixbuf.
+ *
+ * Takes an existing pixbuf and checks for the presence of an
+ * associated "orientation" option, which may be provided by the 
+ * jpeg loader (which reads the exif orientation tag) or the 
+ * tiff loader (which reads the tiff orientation tag, and
+ * compensates it for the partial transforms performed by 
+ * libtiff). If an orientation option/tag is present, the
+ * appropriate transform will be performed so that the pixbuf
+ * is oriented correctly.
+ *
+ * Return value: A newly-created pixbuf, or a reference to the
+ * input pixbuf (with an increased reference count).
+ *
+ * Since 2.12
+ **/
+GdkPixbuf *
+gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src)
+{
+       const gchar *orientation_string;
+       int          transform = 0;
+       GdkPixbuf   *temp;
+       GdkPixbuf   *dest;
+
+       g_return_val_if_fail (src != NULL, NULL);
+
+       /* Read the orientation option associated with the pixbuf */
+       orientation_string = gdk_pixbuf_get_option (src, "orientation");        
+
+       if (orientation_string) {
+               /* If an orientation option was found, convert the 
+                  orientation string into an integer. */
+               transform = (int) g_ascii_strtoll (orientation_string, NULL, 10);
+       }
+
+       /* Apply the actual transforms, which involve rotations and flips. 
+          The meaning of orientation values 1-8 and the required transforms
+          are defined by the TIFF and EXIF (for JPEGs) standards. */
+        switch (transform) {
+        case 1:
+                dest = src;
+                g_object_ref (dest);
+                break;
+        case 2:
+                dest = gdk_pixbuf_flip (src, TRUE);
+                break;
+        case 3:
+                dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
+                break;
+        case 4:
+                dest = gdk_pixbuf_flip (src, FALSE);
+                break;
+        case 5:
+                temp = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                dest = gdk_pixbuf_flip (temp, TRUE);
+                g_object_unref (temp);
+                break;
+        case 6:
+                dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                break;
+        case 7:
+                temp = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                dest = gdk_pixbuf_flip (temp, FALSE);
+                g_object_unref (temp);
+                break;
+        case 8:
+                dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
+                break;
+        default:
+               /* if no orientation tag was present */
+                dest = src;
+                g_object_ref (dest);
+                break;
+        }
+
+        return dest;
+}
+
+
 #define __GDK_PIXBUF_UTIL_C__
 #include "gdk-pixbuf-aliasdef.c"
 
index a582733229fac80a5722d4f82989fdc3a3b5a95b..f440baf3ac32187296881d2d76a58a2022c18f2c 100644 (file)
@@ -593,7 +593,15 @@ gdk_pixbuf_fill (GdkPixbuf *pixbuf,
  * @key: a nul-terminated string.
  * 
  * Looks up @key in the list of options that may have been attached to the
- * @pixbuf when it was loaded. 
+ * @pixbuf when it was loaded, or that may have been attached by another
+ * function using gdk_pixbuf_set_option().
+ *
+ * For instance, the ANI loader provides "Title" and "Artist" options. 
+ * The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot 
+ * options for cursor definitions. The PNG loader provides the tEXt ancillary
+ * chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders
+ * return an "orientation" option string that corresponds to the embedded 
+ * TIFF/Exif orientation tag (if present).
  * 
  * Return value: the value associated with @key. This is a nul-terminated 
  * string that should not be freed or %NULL if @key was not found.
index d29cf7cae149f58f16fda58b1b7d0fe17a3b1dc5..90aed9a4e11f7267fda2c74227ecd25b6304ee9b 100644 (file)
@@ -82,6 +82,7 @@ gdk_pixbuf_new_from_inline
 gdk_pixbuf_add_alpha
 gdk_pixbuf_copy_area
 gdk_pixbuf_saturate_and_pixelate
+gdk_pixbuf_apply_embedded_orientation
 #endif
 #endif